<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-collapse v-model="activeKey">
          <a-collapse-panel key="1" header="基本信息">
        <a-row :gutter="48">
        <a-col :span="8" :hidden="true">
            <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bpmBizTitle">
              <a-input
                :disabled="formDisabled"
                v-model="model.bpmBizTitle"
                placeholder="请输入标题"
                :max-length="255"
              ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billNo">
              <a-input :disabled="formDisabled || billNoDisabled" v-model="model.billNo" placeholder="请输入单据编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="填表时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date :disabled=formDisabled placeholder="请选择填表时间" v-model="model.createTime" :show-time="true"
                      date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="报销人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposer">
              <select-user-by-dep :disabled=formDisabled  :multi="false"
                  v-model="model.proposer" disabled></select-user-by-dep>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
             <a-form-model-item label="所在部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="proposerDeptId">
              <j-select-depart :disabled=formDisabled v-model="model.proposerDeptId" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="申请公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applicant">
             <select-Company-input :disabled="formDisabled" v-model="model.applicant" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="团队费用类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamFeeCategory">
              <j-dict-select-tag  :disabled=formDisabled type="list" v-model="model.teamFeeCategory" dictCode="team_fee_category" placeholder="请选择团队费用类别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
              <a-form-model-item label="费用所属团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
                <select-team-input
                :disabled=formDisabled
                v-model="model.teamId" :tdlx="3" @back="selectTeam"/>
              </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="费用所属年度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamYear">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.teamYear" dictCode="tdnd_type" placeholder="请选择费用所属年度" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="单据类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billCategory">
              <j-dict-select-tag  :disabled=formDisabled type="list" v-model="model.billCategory" dictCode="bill_category" placeholder="请选择单据类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="本次是否付款" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPay">
              <j-dict-select-tag @input="isPay"  :disabled=formDisabled type="list" v-model="model.isPay" dictCode="is_pay" placeholder="请选择本次是否付款" />
            </a-form-model-item>
          </a-col>
           <a-col :span="8">
            <a-form-model-item label="本次付款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payAmount">
              <a-input-number :disabled="formDisabled || isPayDisabled" :max="99999999" :min="0"  v-model="model.payAmount" placeholder="请输入本次付款金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="8">
            <a-form-model-item label="累计报销金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accumulateAmount">
              <a-input-number :disabled="true" :max="99999999" :min="0"  v-model="model.accumulateAmount" placeholder="请输入累计报销金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="16">
            <a-form-model-item label="报销说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyExplain">
              <a-input :disabled=formDisabled v-model="model.applyExplain" placeholder="请输入报销说明"  :max-length="20"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="费用类别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeCategory">
              <j-dict-select-tag :disabled="formDisabled" type="radio" v-model="model.feeCategory"
                                     dictCode="fee_category" placeholder="请选择费用类别"  @input="radioCategory"/>
            </a-form-model-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
        </a-collapse-panel>
        <a-collapse-panel key="2" header="费用报销信息" >
          <a-row :gutter="48">
            <a-col :span="24">
                <!--迭代 start 10TASK#3370 费用报销单-工资福利类修改为子表多条和新增累计报销金额字段 -->
              <div v-if="model.feeCategory==0">
                <div style="margin-bottom: 6px;margin-top: 6px;" >
                  <a-button @click="handleSalaryFeeInfoAdd" v-if="!formDisabled" type="primary">新增</a-button>
                </div>
                <a-table
                    ref="table"
                    size="middle"
                    rowKey="id"
                    :loading="loading"
                    :columns="salaryColumns"
                    :pagination="false"
                    :data-source="model.salaryFeeInfoList"
                    :scroll="{x: true}"
                    >
                    <span slot="action" slot-scope="text, record">
                      <template v-if="!formDisabled">
                        <a-button
                            class="ruleButton"
                            :ghost="true"
                            type="primary"
                            icon="edit"
                            @click="handleSalaryFeeInfoEdit(record)"/>
                        <a-divider type="vertical"/>
                        <a-popconfirm title="确定复制行吗?" @confirm="() => handleSalaryCopy(record)">
                          <a-button
                              class="ruleButton"
                              :ghost="true"
                              type="primary"
                              icon="copy"
                          />
                        </a-popconfirm>
                        <a-divider type="vertical"/>
                        <a-popconfirm title="确定删除吗?" @confirm="() => handleSalaryFeeInfoDelete(record.id)">
                            <a-button
                                class="ruleButton"
                                :ghost="true"
                                type="primary"
                                icon="delete"
                            />
                        </a-popconfirm>
                        <a-divider type="vertical"/>
                      </template>
                    </span>
                </a-table>
              </div>
            </a-col>
            <!--迭代 end 10TASK#3370 费用报销单-工资福利类修改为子表多条和新增累计报销金额字段 -->
            <div v-if="model.feeCategory==1">
              <a-col :span="8">
                <a-form-model-item label="采购大类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.bigCategory">
                  <a-select
                    v-model="model.purchaseyFeeInfo.bigCategory"
                    :disabled="formDisabled"
                    placeholder="请选择采购大类"
                    :showSearch="true"
                    :allowClear="true"
                    :filterOption="filterOption"
                    @change="handleChange"
                    :getPopupContainer="(triggerNode)=>{ return triggerNode.parentNode}"
                  >
                    <a-select-option v-for="item in provisionBroadList" :key="item.id" :value="item.id">{{item.categoryName}}</a-select-option>
                  </a-select>
                  <!-- <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.purchaseyFeeInfo.bigCategory" dictCode="big_category_purchasey" placeholder="请选择采购大类" /> -->
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="采购小类" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.smallCategory">
                  <a-select
                    v-model="model.purchaseyFeeInfo.smallCategory"
                    :disabled="formDisabled || !model.purchaseyFeeInfo.bigCategory "
                    placeholder="请选择采购小类"
                    :showSearch="true"
                    :allowClear="true"
                    :filterOption="filterOption"
                    :getPopupContainer="(triggerNode)=>{ return triggerNode.parentNode}"
                  >
                    <a-select-option v-for="item in provisionSmallList" :key="item.id" :value="item.id">{{item.categoryName}}</a-select-option>
                  </a-select>
                  <!-- <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.purchaseyFeeInfo.smallCategory" dictCode="small_category_purchasey" placeholder="请选择采购小类" /> -->
                </a-form-model-item>
              </a-col>
              <a-col :span="8" >
                <a-form-model-item label="关联采购合同" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.relContractId">
                  <select-purchase-contract-input  :disabled="formDisabled ||  !model.teamId || !model.applicant" :teamId="model.teamId" :demandCompanName="model.applicant" v-model="model.purchaseyFeeInfo.relContractId" style="width: 100%" placeholder="请选择采购合同" @back="getContract" />
                </a-form-model-item>
              </a-col>
               <!-- <a-col :span="8">
                <a-form-model-item label="关联团队" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teamId">
                  <select-team-input
                  :disabled=formDisabled
                  v-model="model.purchaseyFeeInfo.teamId" :tdlx="3" disabled/>
                </a-form-model-item>
              </a-col> -->
              <a-col :span="8">
                <a-form-model-item label="发票类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isSpecial">
                    <!-- 迭代八需求 - 发票类型下拉增加一个”其他“选项，其他和普票相同。 -->
                    <j-dict-select-tag :disabled="formDisabled" type="list" v-model="model.purchaseyFeeInfo.isSpecial"  @input="isSpecial(2)" dictCode="cost_invoice_type" placeholder="请选择发票类型" disabled/>
                  <!-- <j-dict-select-tag :disabled=formDisabled type="list" @input="isSpecial(2)" v-model="model.purchaseyFeeInfo.isSpecial" dictCode="is_special" placeholder="请选择专票属性" /> -->
                </a-form-model-item>
              </a-col>
              <a-col :span="8" >
                <a-form-model-item label="合同款项" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contractPaymentId">
                  <select-purchase-contract-payment-input :multi="true" :disabled=formDisabled v-model="model.purchaseyFeeInfo.contractPaymentId" :purchaseBill="model.purchaseyFeeInfo.relContractId" style="width: 100%" placeholder="请选择合同款项"  @back="getContractPayment"/>
                </a-form-model-item>
              </a-col>
              <!-- <a-col :span="8">
                <a-form-model-item label="付款比例" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.paymentProportion">
                  <a-input :disabled=formDisabled :max="99999999" :min="0" addon-after="%"  v-model="model.purchaseyFeeInfo.paymentProportion" placeholder="请输入付款比例" style="width: 100%" disabled/>
                </a-form-model-item>
              </a-col> -->
              <a-col :span="8">
                <!-- 迭代八需求 - 费用类别-采购类-费用报销信息-付款金额改为应付款金额 -->
                <a-form-model-item label="应付款金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.paymentAmount">
                  <a-input-number :disabled=formDisabled :max="99999999" :min="0" v-model="model.purchaseyFeeInfo.paymentAmount" placeholder="请输入应付款金额" style="width: 100%" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="已付金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.collectedAmount">
                  <a-input-number :disabled=formDisabled :max="99999999" :min="0" v-model="model.purchaseyFeeInfo.collectedAmount" placeholder="请输入已付金额" style="width: 100%" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="未付金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.unpaymentAmount">
                  <a-input-number :disabled=formDisabled :max="99999999" :min="0" v-model="model.purchaseyFeeInfo.unpaymentAmount" placeholder="请输入未付金额" style="width: 100%" disabled />
                </a-form-model-item>
              </a-col>
               <a-col :span="8">
                <a-form-model-item label="报销金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.amount">
                  <a-input-number :disabled=formDisabled :max="model.purchaseyFeeInfo.unpaymentAmount?Number(model.purchaseyFeeInfo.unpaymentAmount):99999999" :min="0" @change="inputAmount(2)" v-model="model.purchaseyFeeInfo.amount" placeholder="请输入报销金额" style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="税费金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.taxation">
                  <a-input-number :disabled="formDisabled || isSpecialDisabled"  @change="inputAmount(2)"  :max="99999999" :min="0"  v-model="model.purchaseyFeeInfo.taxation" placeholder="请输入税费金额" style="width: 100%" />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="未税金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="purchaseyFeeInfo.untaxedAmount">
                  <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.purchaseyFeeInfo.untaxedAmount" placeholder="请输入未税金额" style="width: 100%" disabled />
                </a-form-model-item>
              </a-col>
            </div>
            <a-col :span="24" v-if="model.feeCategory==2">
              <a-col :span="24">
                <a-form-model-item label="是否关联项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isRelProject">
                  <j-dict-select-tag :disabled="formDisabled || model.dailyFeeInfoList.length>0?true:false" type="radio" v-model="model.isRelProject" dictCode="is_rel_project"  placeholder="请选择是否关联项目" />
                </a-form-model-item>
              </a-col>
              <div style="margin-bottom: 6px;margin-top: 6px" >
                <a-button @click="handleAdd" v-if="!formDisabled" type="primary">新增</a-button>
              </div>
              <a-table
                  ref="table"
                  size="middle"
                  rowKey="id"
                  :loading="loading"
                  :columns="model.isRelProject=='1'?columns:precolumns"
                  :pagination="false"
                  :data-source="model.dailyFeeInfoList"
                  :scroll="{x: true}"
                  >
                  <span slot="action" slot-scope="text, record">
                    <template v-if="!formDisabled">
                            <a-button
                                class="ruleButton"
                                :ghost="true"
                                type="primary"
                                icon="edit"
                                @click="handleEdit(record)"/>
                            <a-divider type="vertical"/>
                            <a-popconfirm title="确定复制行吗?" @confirm="() => handleCopy(record)">
                                  <a-button
                                      class="ruleButton"
                                      :ghost="true"
                                      type="primary"
                                      icon="copy"
                                  />
                              </a-popconfirm>
                              <a-divider type="vertical"/>
                            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                                <a-button
                                    class="ruleButton"
                                    :ghost="true"
                                    type="primary"
                                    icon="delete"
                                />
                            </a-popconfirm>
                    </template>
                  </span>
              </a-table>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="结算方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="settleType" v-if="model.isPay" >
                <j-dict-select-tag v-if="model.isPay=='1'" :disabled=formDisabled type="list" v-model="model.settleType" dictCode="settle_type" placeholder="请选择结算方式" @input="radioSettleType"/>
                <j-dict-select-tag v-if="model.isPay=='0'" :disabled=formDisabled type="list" v-model="model.settleType" dictCode="settle_type_false" placeholder="请选择结算方式" @input="radioSettleType"/>
              </a-form-model-item>
            </a-col>
            <template v-if="this.model.settleType==0">
              <a-col :span="8" v-if="this.model.settleType==0">
                <a-form-model-item label="收款户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountName">
                  <a-input :disabled=formDisabled v-model="model.accountName" placeholder="请输入收款户名"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="收款开方户行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankName">
                  <a-input :disabled=formDisabled v-model="model.bankName" placeholder="请输入收款方开户行"  ></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="收款方银行账户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="accountNo">
                  <a-input :disabled=formDisabled v-model="model.accountNo" :max-length="32" placeholder="请输入收款方银行账户"  ></a-input>
                </a-form-model-item>
              </a-col>
            </template>
            <template v-if="model.settleType==2">
              <a-col :span="8">
                <a-form-model-item label="单据类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relBillType">
                  <j-dict-select-tag :disabled=formDisabled type="list" v-if="model.isPay=='0'" v-model="model.relBillType" dictCode="rel_bill_type" placeholder="请选择单据类型"  @input="radioChange" />
                  <j-dict-select-tag :disabled=formDisabled type="list" v-else v-model="model.relBillType" dictCode="rel_bill_type_pay" placeholder="请选择单据类型"  @input="radioChange" />
                </a-form-model-item>
              </a-col>
              <a-col :span="16">
                <a-form-model-item label="关联单据单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="relBillId"  v-if="model.relBillType==1||model.relBillType==2||model.relBillType==3">
                  <select-finance-payment-bill-input :disabled=formDisabled v-model="model.relBillId" v-if="model.relBillType==2" @back="relBillData" placeholder="请选择关联单据单号" />
                  <select-finance-loan-bill-input :disabled=formDisabled v-model="model.relBillId" v-if="model.relBillType==1" @back="relBillData" placeholder="请选择关联单据单号" />
                  <select-finance-deposit-bill-input  :disabled="formDisabled" v-model="model.relBillId" v-if="model.relBillType==3" isReturn="1" @back="relBillData" placeholder="请选择关联单据单号" />
                </a-form-model-item>
              </a-col>
              <template v-if="model.relBillType=='1'">
                <a-col :span="8" >
                  <a-form-model-item label="借款金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="borrowLoanAmount" >
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.borrowLoanAmount" placeholder="请输入借款金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="已还金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="borrowOnloanAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.borrowOnloanAmount" placeholder="请输入已还金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="未还金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="borrowUnloanAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.borrowUnloanAmount" placeholder="请输入未还金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="24" >
                  <a-form-model-item label="支付金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="borrowPayAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.borrowPayAmount" placeholder="请输入支付金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
              </template>
              <template v-if="model.relBillType=='2'">
                <a-col :span="8" >
                  <a-form-model-item label="申请公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payApplicant" >
                    <select-Company-input :disabled="formDisabled" v-model="model.payApplicant" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="收款单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payPayeeName" >
                    <select-customer-input  :disabled="formDisabled" v-model="model.payPayeeName" commercialType="1"  disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" >
                  <a-form-model-item label="付款金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payPayableAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.payPayableAmount" placeholder="请输入付款金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" >
                  <a-form-model-item label="应付金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payPaidAmount"   >
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.payPaidAmount" placeholder="请输入应付金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" >
                  <a-form-model-item label="扣款金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payDeductionAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.payDeductionAmount" placeholder="请输入扣款金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
              </template>
              <template v-if="model.relBillType=='3'">
                <a-col :span="8" >
                  <a-form-model-item label="保证金总额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="depositRemittanceAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.depositRemittanceAmount" placeholder="请输入保证金总额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" >
                  <a-form-model-item label="服务费(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="depositServiceCharge"   >
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.depositServiceCharge" placeholder="请输入服务费" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" >
                  <a-form-model-item label="利息金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="depositInterestAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.depositInterestAmount" placeholder="请输入利息金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" >
                  <a-form-model-item label="归还金额(元)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="depositReturnAmount">
                    <a-input-number :disabled=formDisabled :max="99999999" :min="0"  v-model="model.depositReturnAmount" placeholder="请输入归还金额" style="width: 100%" disabled/>
                  </a-form-model-item>
                </a-col>
              </template>
            </template>
<!--            <a-col :span="24">-->
<!--              <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">-->
<!--                <a-textarea :disabled=formDisabled v-model="model.remark" rows="4" placeholder="请输入备注" :max-length="500"/>-->
<!--              </a-form-model-item>-->
<!--            </a-col>-->
          </a-row>
        </a-collapse-panel>
        <a-collapse-panel key="3" header="附件信息" >
          <a-row :gutter="48">
            <a-col :span="24">
              <a-form-model-item label="附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="attachments">
                <j-upload :disabled=formDisabled v-model="model.attachments"   ></j-upload>
              </a-form-model-item>
            </a-col>
          </a-row>
          </a-collapse-panel>
        </a-collapse>
      </a-form-model>
      <!--子表表单-->
      <erp-finance-reimbursement-salary-fee-modal ref="salaryFee" @ok="modalSalaryFeeInfoFormOk"></erp-finance-reimbursement-salary-fee-modal>
      <erp-finance-reimbursement-daily-fee-info-modal ref="dailyFee" @ok="modalFormOk" :teamId="model.teamId" :applicant="model.applicant"></erp-finance-reimbursement-daily-fee-info-modal>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import moment from 'moment'
  import { mapGetters } from 'vuex'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectPersonInput from '@/views/scy/components/SelectPersonInput'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import { filterMultiDictText, initDictOptions } from '@/components/dict/JDictSelectUtil'
  import ErpFinanceReimbursementDailyFeeInfoModal from './ErpFinanceReimbursementDailyFeeInfoModal'
  import SelectFinanceLoanBillInput from '@/views/scy/components/SelectFinanceLoanBillInput'
  import SelectFinancePaymentBillInput from '@/views/scy/components/SelectFinancePaymentBillInput'
  import SelectContractManagerInput from '@/views/scy/components/SelectContractManagerInput'
  import SelectPurchaseContractInput from '@/views/scy/components/SelectPurchaseContractInput'
  import SelectProjectInput from '@/views/scy/components/SelectProjectInput'
  import SelectPurchaseContractPaymentInput from '@/views/scy/components/SelectPurchaseContractPaymentInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import SelectFinanceDepositBillInput from '@/views/scy/components/SelectFinanceDepositBillInput'
  import JDictSelectCategory from '@/components/dict/JDictSelectCategory.vue'
  import ErpFinanceReimbursementSalaryFeeModal from './ErpFinanceReimbursementSalaryFeeModal'

  export default {
    name: 'ErpFinanceReimbursementBillForm',
    components: {
      JDictSelectCategory,
      SelectFinanceDepositBillInput,
      SelectCustomerInput,
      SelectCompanyInput,
      SelectProjectInput,
      SelectUserByDep,
      SelectPersonInput,
      SelectTeamInput,
      SelectFinanceLoanBillInput,
      ErpFinanceReimbursementDailyFeeInfoModal,
      SelectContractManagerInput,
      SelectFinancePaymentBillInput,
      SelectPurchaseContractInput,
      SelectPurchaseContractPaymentInput,
      ErpFinanceReimbursementSalaryFeeModal
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    watch: {
      activeKey(key) {
        this.$forceUpdate()
      }
    },
    data () {
      return {
        isSpecialDisabled:false,//发票类型
        billNoDisabled:true,//是否单号
        isPayDisabled:false,//是否付款
        activeKey: ['1','2','3'],
        provisionSmallList:[],
        provisionBroadList:[],
        model:{
          feeCategory:'0',
          salaryFeeInfoList:[],
          purchaseyFeeInfo:{
            taxation:0
          },
          isRelProject:"1",
          dailyFeeInfoList:[],
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
          bpmBizTitle: [
              { required: true, message: '请输入流程标题!'},
          ],
          // salaryFeeInfo:{
          //   bigCategory:[{ required: true, message: '请输入工资福利大类!'}],
          //   smallCategory:[{ required: true, message: '请输入工资福利小类!'},],
          //   amount:[ { required: true,pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},],
          //   isSpecial:[ { required: true, message: '请选择发票类型!'},]
          // },
          purchaseyFeeInfo:{
            bigCategory:[{ required: true, message: '请输入采购大类!'}],
            smallCategory:[{ required: true, message: '请输入采购小类!'},],
            amount:[ { required: true,pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},],
            // 迭代10#TASK3371 费用报销单-采购类-费用报销信息-关联采购合同改为必填项
            relContractId:[
              { required: true, message: '请选择关联采购合同!'},
            ],
          },
          billCategory: [
              { required: true, message: '请选择单据类型!'},
          ],
          teamFeeCategory: [
              { required: true, message: '请选择团队费用类别!'},
          ],
          teamId: [
              { required: true, message: '请选择费用所属团队!'},
          ],
          payAmount: [
            { required: true,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},
          ],
          applyExplain: [
              { required: true, message: '请输入报销说明!'},
          ],
          applicant: [
              { required: true, message: '请输入申请公司!'},
          ],
          isPay: [
              { required: true, message: '请输入是否付款!'},
          ],
          feeCategory: [
              { required: true, message: '请输入费用类别!'},
          ],
          settleType: [
              { required: true, message: '请输入结算方式!'},
          ],
          accountName: [
              { required: true, message: '请输入收款户名!'},
          ],
          bankName: [
              { required: true, message: '请输入收款方开户行!'},
          ],
          accountNo: [
               { required: true, message: '请输入收款方银行账户!' },
              // { pattern: /^[1-9]{1}\d{7,29}$/, message: '请输入正确的银行账户!' },
          ],
          relBillType:[
              { required: true, message: '请选择单据类型!'},
          ],
          relBillId:[
              { required: true, message: '请选择关联的单据!'},
          ],
          // onloanAmount:[ { required: false,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},],
          // unloanAmount:[ { required: false,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},],
          // loanAmount:[ { required: false,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'},]
        },
        url: {
          getBillNo:"/api/erp/finance/reimbursement/erpFinanceReimbursementBill/getBillNo",
          add: "/api/erp/finance/reimbursement/erpFinanceReimbursementBill/add",
          edit: "/api/erp/finance/reimbursement/erpFinanceReimbursementBill/edit",
          queryById: "/api/erp/finance/reimbursement/erpFinanceReimbursementBill/queryById",
          queryProvisionBroadList: "/api/erp/purchase/material/erpMaterialCategory/queryAllParent",
          queryProvisionSmallList: "/api/erp/purchase/material/erpMaterialCategory/queryChildrenByParentId"
        },
        loading: false,
        dictOptions: {},
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title:'项目名称',
            align:"center",
            dataIndex: 'projectId',
            customRender: (text,r) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['projectId'], text + '')
              }
            }
          },
          {
            title:'任务分类',
            align:"center",
            dataIndex: 'taskCategory',
            customRender: (text,r) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['taskCategory'], text + '')
              }
            }
          },
          {
            title:'任务说明',
            align:"center",
            dataIndex: 'taskName',
          },
          // 迭代八需求文档 - 3.1.9 费用报销单 费用类别-费用类-费用报销信息-子表-新增（含列表）删除费用所属团队和费用所属年度两个字段
          // {
          //   title:'费用所属年度',
          //   align:"center",
          //   dataIndex: 'teamYear',
          //   customRender: (text) => {
          //     if (!text) {
          //       return ''
          //     } else {
          //       return filterMultiDictText(this.dictOptions['teamYear'], text + '')
          //     }
          //   }
          // },
          // {
          //   title:'费用所属团队',
          //   align:"center",
          //   dataIndex: 'teamId',
          //   customRender: (text) => {
          //     if (!text) {
          //       return ''
          //     } else {
          //       return filterMultiDictText(this.dictOptions['teamId'], text + '')
          //     }
          //   }
          // },
          {
            title:'业绩归属年度',
            align:"center",
            dataIndex: 'performanceAttributionYear',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['performanceAttributionYear'], text + '')
              }
            }
          },
          {
            title:'费用大类',
            align:"center",
            dataIndex: 'bigCategory',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['bigCategory'], text + '')
              }
            }
          },
          {
            title:'费用小类',
            align:"center",
            dataIndex: 'smallCategory',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['smallCategory'], text + '')
              }
            }
          },
          {
            title:'发票类型',
            align:"center",
            dataIndex: 'isSpecial',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['isSpecial'], text + '')
              }
            }
          },
          {
            title:'报销金额',
            align:"center",
            dataIndex: 'amount',
          },
          {
            title:'税费金额',
            align:"center",
            dataIndex: 'taxation',
          },
          {
            title:'未税金额',
            align:"center",
            dataIndex: 'untaxedAmount',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: {
              filterDropdown: 'filterDropdown',
              filterIcon: 'filterIcon',
              customRender: 'action'
            }
          }
        ],
        precolumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },

          {
            title:'费用大类',
            align:"center",
            dataIndex: 'bigCategory',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['bigCategory'], text + '')
              }
            }
          },
          {
            title:'费用小类',
            align:"center",
            dataIndex: 'smallCategory',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['smallCategory'], text + '')
              }
            }
          },
          {
            title:'发票类型',
            align:"center",
            dataIndex: 'isSpecial',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['isSpecial'], text + '')
              }
            }
          },
          {
            title:'报销金额',
            align:"center",
            dataIndex: 'amount',
          },
          {
            title:'税费金额',
            align:"center",
            dataIndex: 'taxation',
          },
          {
            title:'未税金额',
            align:"center",
            dataIndex: 'untaxedAmount',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: {
              filterDropdown: 'filterDropdown',
              filterIcon: 'filterIcon',
              customRender: 'action'
            }
          }
        ],
        salaryColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },

          {
            title:'工资福利大类',
            align:"center",
            dataIndex: 'bigCategory',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['bigCategory'], text + '')
              }
            }
          },
          {
            title:'工资福利小类',
            align:"center",
            dataIndex: 'smallCategory',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['smallCategory'], text + '')
              }
            }
          },
          {
            title:'发票类型',
            align:"center",
            dataIndex: 'isSpecial',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(this.dictOptions['isSpecial'], text + '')
              }
            }
          },
          {
            title:'报销金额(元)',
            align:"center",
            dataIndex: 'amount',
          },
          {
            title:'税费金额(元)',
            align:"center",
            dataIndex: 'taxation',
          },
          {
            title:'未税金额(元)',
            align:"center",
            dataIndex: 'untaxedAmount',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: {
              filterDropdown: 'filterDropdown',
              filterIcon: 'filterIcon',
              customRender: 'action'
            }
          }
        ]
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
      //加载数据字典信息
      this.initDictConfig();
      if(this.formDisabled){
        this.columns.pop()
        this.precolumns.pop()
        this.salaryColumns.pop()
      }
    },
    methods: {
      //修改大类，清空小类
      modifyCategory(data){
        if(data){
          if(this.model.salaryFeeInfo.smallCategory){
            this.$set(this.model.salaryFeeInfo,"smallCategory",null);
          }
        }
      },
      selectTeam(data){
        this.model.teamYear=data[0].tdnd;
        //工资福利类
        if(this.model.feeCategory=='1'){
          if(this.model.purchaseyFeeInfo.relContractId){
            this.model.purchaseyFeeInfo={};
          }
          //费用类
        }else if(this.model.feeCategory=='2'){
          if(this.model.dailyFeeInfoList){
              this.model.dailyFeeInfoList=[];
          }
        }

      },
      //获取合同详情
      getContract(data){
        if(data){
          this.$set(this.model.purchaseyFeeInfo,"teamId",data[0].teamId);
          this.$set(this.model.purchaseyFeeInfo,"isSpecial",data[0].invoiceCategory);
          this.$set(this.model.purchaseyFeeInfo, 'relBillType',);
          this.isSpecial(2);
          if(this.model.purchaseyFeeInfo.contractPaymentId){
            this.$set(this.model.purchaseyFeeInfo,"contractPaymentId",null);
            this.$set(this.model.purchaseyFeeInfo,"paymentProportion",null);
            this.$set(this.model.purchaseyFeeInfo,"paymentAmount",null);
          }
        }
      },
      getContractPayment(data){
        if(data.length>0){
          let paymentAmount=0;
          let paymentTotalAmount=0;
          for(var i=0;i<data.length;i++){
            paymentAmount+=data[i].paymentAmount;
            paymentTotalAmount+=data[i].paymentTotalAmount;
          }
          this.$set(this.model.purchaseyFeeInfo,"paymentAmount",paymentAmount.toFixed(2));
          this.$set(this.model.purchaseyFeeInfo,"collectedAmount",paymentTotalAmount.toFixed(2));
          this.$set(this.model.purchaseyFeeInfo,"unpaymentAmount",(paymentAmount-paymentTotalAmount).toFixed(2));
        }else{
          this.$set(this.model.purchaseyFeeInfo,"paymentAmount",0);
          this.$set(this.model.purchaseyFeeInfo,"collectedAmount",0);
          this.$set(this.model.purchaseyFeeInfo,"unpaymentAmount",0);
        }
        this.isSpecial(2);
      },
      //修改
      handleChange(value) {
        this.provisionSmallList = []
        this.$set(this.model.purchaseyFeeInfo, 'smallCategory', undefined);
        this.$refs["form"].clearValidate('purchaseyFeeInfo.smallCategory');
        if (!!value) {
          this.findProvisionSmallList(value)
        }
      },
      //大类
      findProvisionBroadList() {
        const that = this
        that.provisionBroadList = []
        getAction(this.url.queryProvisionBroadList).then(res => {
          if (res.success) {
            res.result.forEach((res) => {
              that.provisionBroadList.push({ 'id':res.id, 'categoryName':res.categoryName })
            })
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      //小类
      findProvisionSmallList(value) {
        const that = this
        const parentId = value
        getAction(this.url.queryProvisionSmallList, { parentId }).then(res => {
          if (res.success) {
            res.result.forEach((res) => {
              that.provisionSmallList.push({ 'id':res.id, 'categoryName':res.categoryName })
            })
          } else {
            that.$message.warning(res.message)
          }
        })
      },
      //筛选
      filterOption(input, option) {
        return (
          option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
        );
      },
      //切换结算方式
      radioSettleType(ops){
        if(ops=='0'){//转账
          this.$refs["form"].clearValidate('relBillId');
          this.$set(this.model, 'relBillType',null);
          this.$set(this.model, 'relBillId', '');
          this.$set(this.model, 'borrowPayAmount', '');
          this.$set(this.model, 'borrowOnloanAmount', '');
          this.$set(this.model, 'borrowLoanAmount', '');
          this.$set(this.model, 'borrowUnloanAmount', '');
        }else if(ops=='2'){//冲账
          this.$refs["form"].clearValidate('accountName');
          this.$refs["form"].clearValidate('bankName');
          this.$refs["form"].clearValidate('accountNo');
          this.$set(this.model, 'accountName', '');
          this.$set(this.model, 'bankName', '');
          this.$set(this.model, 'accountNo', '');
        }else{
          this.$set(this.model, 'relBillType', null);
          this.$set(this.model, 'relBillId', '');
          this.$set(this.model, 'borrowPayAmount', '');
          this.$set(this.model, 'borrowOnloanAmount', '');
          this.$set(this.model, 'borrowLoanAmount', '');
          this.$set(this.model, 'borrowUnloanAmount', '');
          this.$set(this.model, 'accountName', '');
          this.$set(this.model, 'bankName', '');
          this.$set(this.model, 'accountNo', '');
        }
      },
      //切换费用类别分类
      radioCategory(){
        this.$set(this.model,'accumulateAmount',0);
        this.$set(this.model,'salaryFeeInfo',{});
        this.$set(this.model,'salaryFeeInfoList',[]);
        this.$set(this.model,'purchaseyFeeInfo',{});
        this.$set(this.model,'dailyFeeInfoList',[]);
        this.$set(this.model,'isRelProject',"1");
        this.$set(this.model.purchaseyFeeInfo,'taxation',0);
        this.$set(this.model.salaryFeeInfo,'taxation',0);
      },
       //修改按钮
      radioChange () {
        if(this.model.relBillId){
          this.$set(this.model, 'relBillId', '');
          this.$set(this.model, 'borrowPayAmount', '');
          this.$set(this.model, 'borrowOnloanAmount', '');
          this.$set(this.model, 'borrowLoanAmount', '');
          this.$set(this.model, 'borrowUnloanAmount', '');
          this.$set(this.model, 'payApplicant', '');
          this.$set(this.model, 'payPayeeName', '');
          this.$set(this.model, 'payPayableAmount', '');
          this.$set(this.model, 'payPaidAmount', '');
          this.$set(this.model, 'payDeductionAmount', '');
          this.$set(this.model, 'depositRemittanceAmount', '');
          this.$set(this.model, 'depositReturnAmount', '');
          this.$set(this.model, 'depositServiceCharge', '');
          this.$set(this.model, 'depositInterestAmount', '');
        }
      },
      //获取编号
      getBillNo(){
        let that=this;
        getAction(this.url.getBillNo, {}).then((res) => {
          if (res.success) {
            let data = res.result.records || res.result
            this.$set(this.model, 'billNo', data);
            this.$set(this.model, 'bpmBizTitle', this.userInfo().employee.name+'-'+data);
            this.billNoDisabled=true;
          }
        })
      },
      //发票类型
      isSpecial(arg){
        console.log(arg);
        if(arg==1){//工资福利
          // if(this.model.salaryFeeInfo.isSpecial!=1){//不是专票
              // this.$set(this.model.salaryFeeInfo, 'taxation',0);
              // this.isSpecialDisabled=true;
              // this.inputAmount(1);
              // this.$refs.form.clearValidate('salaryFeeInfo.taxation');
              // this.$set(this.validatorRules.salaryFeeInfo, 'taxation', [{ required: false,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'}]);
          // }else{
            // this.$refs.form.clearValidate('salaryFeeInfo.taxation');
            // this.$set(this.validatorRules.salaryFeeInfo, 'taxation', [{ required: true,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'}]);
            // this.isSpecialDisabled=false;
          // }
        }else if(arg==2){//采购
          if(this.model.purchaseyFeeInfo.isSpecial!=1){//不是专票
              this.$set(this.model.purchaseyFeeInfo, 'taxation',0);
              this.isSpecialDisabled=true;
              this.inputAmount(2);
              this.$refs.form.clearValidate('purchaseyFeeInfo.taxation');
              this.$set(this.validatorRules.purchaseyFeeInfo, 'taxation', [{ required: false,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'}]);
          }else{
             this.$refs.form.clearValidate('purchaseyFeeInfo.taxation');
            this.$set(this.validatorRules.purchaseyFeeInfo, 'taxation', [{ required: true,pattern: /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!'}]);
            this.isSpecialDisabled=false;
          }
        }
      },
      //关联单号
      relBillData(data){
        let id=this.model.relBillId;
        if(this.model.relBillType=="1"){//借款单
          getAction("/api/erp/finance/borrow/erpFinanceLoanBill/queryById",{'id':id}).then((res) => {
            if (res.success) {
                let data=res.result;
                let loanAmount=data.amount;//借款金额
                let onloanAmount=data.repaymentAmount+data.travelReimbursementAmount+data.expenseReimbursementAmount;//已还金额
                let unloanAmount=loanAmount-onloanAmount;
                let amount=0;//报销金额
                if(this.model.feeCategory=="0"){
                  // amount=this.model.salaryFeeInfo.amount;
                  amount=this.model.accumulateAmount;
                }else if(this.model.feeCategory=="1"){
                  amount=this.model.purchaseyFeeInfo.amount;
                }else if(this.model.feeCategory=="2"){
                  this.model.dailyFeeInfoList.forEach(item =>{
                    amount+=item.amount;
                  })
                }
                let loadPayAmount=(amount-unloanAmount).toFixed(2);
                this.$set(this.model,'borrowLoanAmount',loanAmount);
                this.$set(this.model,'borrowOnloanAmount',onloanAmount);
                this.$set(this.model,'borrowUnloanAmount',unloanAmount);
                if(loadPayAmount>0){
                  this.$set(this.model,'borrowPayAmount',loadPayAmount);
                }else{
                  this.$set(this.model,'borrowPayAmount',0);
                }
            }
          })
        }else if(this.model.relBillType=="2"){//付款单
          getAction("/api/erp/finance/payment/erpFinancePaymentSlipFeeDetail/queryBillInfoByBillId",{'billId':id}).then((res) => {
            if (res.success) {
                let resResult=res.result.records[0];
                if(resResult.projectFeeType!='1'){
                  this.$message.error('选择的付款单不是预付款的申请单');
                  this.$set(this.model,'relBillId','');
                  this.$set(this.model,'payPayableAmount','');
                  this.$set(this.model,'payPaidAmount','');
                  this.$set(this.model,'payDeductionAmount','');
                  this.$set(this.model,'payApplicant',null);
                  this.$set(this.model,'payPayeeName',null);
                  return;
                }
                let payApplicant=data[0].applicant;//申请公司
                let payPayeeName=data[0].payeeName//收款单位
                let payPayableAmount=resResult.payableAmount;//应付金额
                let payPaidAmount=resResult.currentPaidAmount;//本次支付金额
                let payDeductionAmount=resResult.currentDeductionAmount;//本次扣款金额
                this.$set(this.model,'payPayableAmount',payPayableAmount);
                this.$set(this.model,'payPaidAmount',payPaidAmount);
                this.$set(this.model,'payDeductionAmount',payDeductionAmount);
                this.$set(this.model,'payApplicant',payApplicant);
                this.$set(this.model,'payPayeeName',payPayeeName);
            }
          })
        }else if(this.model.relBillType=="3"){//保证金
            let depositRemittanceAmount=data[0].remittanceAmount;//保证金总额
            let depositReturnAmount=data[0].returnAmount//归还总额
            let depositServiceCharge=data[0].serviceCharge;//服务费金额
            let depositInterestAmount=data[0].interestAmount;//利息金额
            this.$set(this.model,'depositRemittanceAmount',depositRemittanceAmount);
            this.$set(this.model,'depositReturnAmount',depositReturnAmount);
            this.$set(this.model,'depositServiceCharge',depositServiceCharge);
            this.$set(this.model,'depositInterestAmount',depositInterestAmount);
        }
      },
      //输入报销金额
      inputAmount(arg){
        if(arg==1){//工资福利
        
          if(this.model.borrowPayAmount!=undefined && this.model.borrowPayAmount!=null){
            // 报销金额 - 未还金额 
            // let borrowPayAmount=(this.model.salaryFeeInfo.amount-this.model.borrowUnloanAmount).toFixed(2);
            let borrowPayAmount=(this.model.accumulateAmount-this.model.borrowUnloanAmount).toFixed(2);
            if(borrowPayAmount>0){
              this.$set(this.model,'borrowPayAmount',borrowPayAmount);
            }else{
              this.$set(this.model,'borrowPayAmount',0);
            }
          }
          // taxation 税费金额=0
          // if(this.model.salaryFeeInfo.amount && (this.model.salaryFeeInfo.taxation || this.model.salaryFeeInfo.taxation==0)){
          //   // 未税金额 = 报销金额 - 税费金额 
          //   this.model.salaryFeeInfo.untaxedAmount=(this.model.salaryFeeInfo.amount-this.model.salaryFeeInfo.taxation).toFixed(2);
          // }
        }else if(arg==2){//采购
          if(this.model.borrowPayAmount!=undefined && this.model.borrowPayAmount!=null){
            let borrowPayAmount=(this.model.purchaseyFeeInfo.amount-this.model.borrowUnloanAmount).toFixed(2);
            if(borrowPayAmount>0){
              this.$set(this.model,'borrowPayAmount',borrowPayAmount);
            }else{
              this.$set(this.model,'borrowPayAmount',0);
            }
          }
          if(this.model.purchaseyFeeInfo.amount && (this.model.purchaseyFeeInfo.taxation || this.model.purchaseyFeeInfo.taxation==0)){
              this.model.purchaseyFeeInfo.untaxedAmount=(this.model.purchaseyFeeInfo.amount-this.model.purchaseyFeeInfo.taxation).toFixed(2);
          }
          // 累计报销金额
          if(this.model.purchaseyFeeInfo.amount){
            this.$set(this.model,'accumulateAmount',this.model.purchaseyFeeInfo.amount.toFixed(2));
          }
        }else if(arg==3){//费用
           if(this.model.borrowPayAmount!=undefined && this.model.borrowPayAmount!=null){
            let dailyFeeInfoList=this.model.dailyFeeInfoList;
            let amount=0;
            dailyFeeInfoList.forEach(item=>{
              amount+=item.amount;
            })
            let borrowPayAmount=(amount-this.model.borrowUnloanAmount).toFixed(2);
            if(borrowPayAmount>0){
              this.$set(this.model,'borrowPayAmount',borrowPayAmount);
            }else{
              this.$set(this.model,'borrowPayAmount',0);
            }
            // 累计报销金额
            this.$set(this.model,'accumulateAmount',amount.toFixed(2));
          }
        }
      },
      //判断是否付款
      isPay(){
        if(this.model.isPay==0){//未付款
          this.$set(this.model,'settleType',null);
          this.$set(this.model,'relBillType',null);
          this.$set(this.model,'payAmount',0);
          this.isPayDisabled=true;
        }else{
          this.$set(this.model,'settleType',null);
          this.$set(this.model,'relBillType',null);
          this.radioSettleType(null);
          this.isPayDisabled=false;
        }
      },
      //加载数据字典信息
      async initDictConfig() {
        initDictOptions('erp_omc_team_manager,alias_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'teamId', res.result)
          }
        })
        initDictOptions('tdnd_type').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'teamYear', res.result)
          }
        })
        initDictOptions('sys_category,name,code').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'bigCategory', res.result)
            this.$set(this.dictOptions, 'smallCategory', res.result)
          }
        })
        initDictOptions('cost_invoice_type').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'isSpecial', res.result)
          }
        })
        initDictOptions('yjgsnd').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'performanceAttributionYear', res.result)
          }
        })
        initDictOptions('erp_omc_project,project_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'projectId', res.result)
          }
        })
        initDictOptions('erp_omc_project_task,category_name,id').then(async(res) => {
          if (res.success) {
            this.$set(this.dictOptions, 'taskCategory', res.result)
          }
        })
      },
      //子表新增
    handleAdd() {
      let flag=this.model.isRelProject=="1"?true:false;
      this.$refs.dailyFee.add(flag);
      this.$refs.dailyFee.title = '新增';
      this.$refs.dailyFee.disableSubmit = false;
    },
    //子表编辑
    handleEdit(record) {
      let flag=this.model.isRelProject=="1"?true:false;
      this.$refs.dailyFee.edit(record,flag);
      this.$refs.dailyFee.title = '修改';
      this.$refs.dailyFee.disableSubmit = false;
    },
    //子表复制行
    handleCopy(record) {
      let model = Object.assign({}, record);
      model.id=parseInt(Math.random() * 1000000000000);
      this.model.dailyFeeInfoList.push(JSON.parse(JSON.stringify(model)))
      // 计算总金额
      let accumulateAmount = 0
      this.model.dailyFeeInfoList.forEach(dailyFeeInfo=>{
        accumulateAmount+=dailyFeeInfo.amount;
      })
      this.model.accumulateAmount =  accumulateAmount.toFixed(2)
    },
    //子表删除
    handleDelete(id) {
      for (let i = 0; i < this.model.dailyFeeInfoList.length; i++) {
        if (this.model.dailyFeeInfoList[i].id == id) {
          this.model.dailyFeeInfoList.splice(i, 1);
        }
      }
      // 计算总金额
      let accumulateAmount = 0
      this.model.dailyFeeInfoList.forEach(dailyFeeInfo=>{
        accumulateAmount+=dailyFeeInfo.amount;
      })
      this.model.accumulateAmount =  accumulateAmount.toFixed(2)
      this.inputAmount(3);
    },
    modalFormOk(data) {
      this.loading = true;
      let flag = true;
      for (let i = 0; i < this.model.dailyFeeInfoList.length; i++) {
        if (this.model.dailyFeeInfoList[i].id == data.id) {
          this.model.dailyFeeInfoList.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.model.dailyFeeInfoList.push(data);
      }
      // 计算总金额
      let accumulateAmount = 0
      this.model.dailyFeeInfoList.forEach(dailyFeeInfo=>{
        accumulateAmount+=dailyFeeInfo.amount;
      })
      this.model.accumulateAmount =  accumulateAmount.toFixed(2)
      this.loading = false;
      this.inputAmount(3);
    },
      ...mapGetters(['userInfo']),
      add () {
        //处理数据为空
        this.$set(this.modelDefault,'salaryFeeInfo',{});
        this.$set(this.modelDefault,'salaryFeeInfoList',[]);
        this.$set(this.modelDefault,'purchaseyFeeInfo',{});
        this.$set(this.modelDefault,'dailyFeeInfoList',[]);
        this.edit(this.modelDefault);
        this.getBillNo();
        this.model.proposer = this.userInfo().empId;
        this.model.proposerDeptId = this.userInfo().deptId;
        //this.model.applicant = this.userInfo().employee.orgDepart; //当前登录人单位
        this.model.createTime = moment().format('YYYY-MM-DD HH:mm:ss');
        this.$set(this.model.purchaseyFeeInfo,'taxation',0);
        this.$set(this.model.salaryFeeInfo,'taxation',0);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        if(record.isPay==0){//是否付款
          this.isPayDisabled=true;
        }
        // if(record.settleType=="2"){//是否关联单据
        //   if(this.model.relBillType=="1"){
        //     this.relBillData();
        //   }
        // }
        this.isSpecial(record.feeCategory=='0'?1:(record.feeCategory=='1'?2:3));
        if (this.model.purchaseyFeeInfo) {
          this.findProvisionBroadList();
          if(this.model.purchaseyFeeInfo.bigCategory){
            this.findProvisionSmallList(this.model.purchaseyFeeInfo.bigCategory)
          }
        }
        this.visible = true;
      },

      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      //判断付款金额是否大于支付金额
      handleAmount(){
        let model=this.model;
        let borrowPayAmount=model.borrowPayAmount
        if((borrowPayAmount || borrowPayAmount==0 ) && this.model.settleType=="2"){//支付金额
          if(borrowPayAmount<model.payAmount){
            return true;
          }
        }
        return false;
      },
      //支付金额数据判断
      handlePayAmount(){
        let model=this.model;
        let feeCategory=model.feeCategory
        let payAmount=model.payAmount
        if(feeCategory=="0"){//工资福利
            // if(payAmount>model.salaryFeeInfo.amount){
              if(payAmount>model.accumulateAmount){
              return true;
            }
        }else if(feeCategory=="1"){//采购
            if(payAmount>model.purchaseyFeeInfo.amount){
              return true;
            }
        }else if(feeCategory=="2"){//费用类
            let data=model.dailyFeeInfoList;
            let amount=0;
            data.forEach(item=>{
              amount+=item.amount;
            })
            if(payAmount>amount){
              return true;
            }
        }
        return false;
      },
      //判断报销金额是否大于冲账金额
      handleChargedAmount(){
        let model=this.model;
        //冲账
        if(model.settleType=='2'){
          if(model.relBillType=='2'){
            let feeCategory=model.feeCategory
            let payAmount=model.payPaidAmount
            if(feeCategory=="0"){//工资福利
                // if(payAmount!=model.salaryFeeInfo.amount){
                if(payAmount!=model.accumulateAmount){
                  return true;
                }
            }else if(feeCategory=="1"){//采购
                if(payAmount!=model.purchaseyFeeInfo.amount){
                  return true;
                }
            }else if(feeCategory=="2"){//费用类
                let data=model.dailyFeeInfoList;
                let amount=0;
                data.forEach(item=>{
                  amount+=item.amount;
                })
                if(payAmount!=amount){
                  return true;
                }
            }
          }
        }
        return false;
      },
      //判断报销金额是否大于保证金服务费金额
      handleDepositChargedAmount(){
        let model=this.model;
        //冲账
        if(model.settleType=='2'){
          if(model.relBillType=='3'){
            let feeCategory=model.feeCategory
            let payAmount=model.depositServiceCharge
            if(feeCategory=="0"){//工资福利
                // if(payAmount!=model.salaryFeeInfo.amount){
                if(payAmount!=model.accumulateAmount){
                  return true;
                }
            }else if(feeCategory=="1"){//采购
                if(payAmount!=model.purchaseyFeeInfo.amount){
                  return true;
                }
            }else if(feeCategory=="2"){//费用类
                let data=model.dailyFeeInfoList;
                let amount=0;
                data.forEach(item=>{
                  amount+=item.amount;
                })
                if(payAmount!=amount){
                  return true;
                }
            }
          }
        }
        return false;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            if(this.handleAmount()){
              that.$message.warning('本次付款金额不能大于支付金额');
              that.confirmLoading = false;
              that.$emit('unButtonDisable');
              return ;
            }
            if(this.handlePayAmount()){
              that.$message.warning('支付金额不能大于报销金额');
              that.confirmLoading = false;
              that.$emit('unButtonDisable');
              return ;
            }
            if(this.handleChargedAmount()){
              that.$message.warning('报销金额只能等于付款单的支付金额');
              that.confirmLoading = false;
              that.$emit('unButtonDisable');
              return ;
            }
            if(this.handleDepositChargedAmount()){
              that.$message.warning('报销金额只能等于保证金的服务费金额');
              that.confirmLoading = false;
              that.$emit('unButtonDisable');
              return ;
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
                that.$emit('unButtonDisable');
              }
            }).catch(()=>{
              that.$emit('unButtonDisable');
            })
            .finally(() => {
              that.confirmLoading = false;

            })
          } else {
            that.$emit('unButtonDisable');
          }

        })
      },
      // 工资福利类改为子表 start
      //工资福利类子表新增
      handleSalaryFeeInfoAdd() {
        this.$refs.salaryFee.add();
        this.$refs.salaryFee.title = '新增';
        this.$refs.salaryFee.disableSubmit = false;
      },
      //子表编辑
      handleSalaryFeeInfoEdit(record) {
        this.$refs.salaryFee.edit(record);
        this.$refs.salaryFee.title = '修改';
        this.$refs.salaryFee.disableSubmit = false;
      },
      //子表复制行
      handleSalaryCopy(record) {
        let model = Object.assign({}, record);
        model.id=parseInt(Math.random() * 1000000000000);
        this.model.salaryFeeInfoList.push(JSON.parse(JSON.stringify(model)))
        // 计算总金额
        let accumulateAmount = 0
        this.model.salaryFeeInfoList.forEach(salaryFeeInfo=>{
          accumulateAmount+=salaryFeeInfo.amount;
        })
        this.model.accumulateAmount =  accumulateAmount.toFixed(2)
      },
      //子表删除
      handleSalaryFeeInfoDelete(id) {
        for (let i = 0; i < this.model.salaryFeeInfoList.length; i++) {
          if (this.model.salaryFeeInfoList[i].id == id) {
            this.model.salaryFeeInfoList.splice(i, 1);
          }
        }
        // 计算总金额
      let accumulateAmount = 0
      this.model.salaryFeeInfoList.forEach(salaryFeeInfo=>{
        accumulateAmount+=salaryFeeInfo.amount;
      })
      this.model.accumulateAmount =  accumulateAmount.toFixed(2)
        this.inputAmount(1);
      },
      // 子表提交
      modalSalaryFeeInfoFormOk(data) {
      this.loading = true;
      let flag = true;
      for (let i = 0; i < this.model.salaryFeeInfoList.length; i++) {
        if (this.model.salaryFeeInfoList[i].id == data.id) {
          this.model.salaryFeeInfoList.splice(i, 1, data);
          flag = false;
        }
      }
      if (flag) {
        this.model.salaryFeeInfoList.push(data);
      }
      // 计算总金额
      let accumulateAmount = 0
      this.model.salaryFeeInfoList.forEach(salaryFeeInfo=>{
        accumulateAmount+=salaryFeeInfo.amount;
      })
      this.model.accumulateAmount =  accumulateAmount.toFixed(2)
      this.loading = false;
      this.inputAmount(1);
    },

    }
  }
</script>
